Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve file hashing #114

Merged
merged 8 commits into from
Nov 15, 2024
Merged

Improve file hashing #114

merged 8 commits into from
Nov 15, 2024

Conversation

gligneul
Copy link
Contributor

@gligneul gligneul commented Nov 2, 2024

Description

This PR improves the file hashing algorithm by parallelizing the file IO and the hashing accumulation. It also adds a unit test to ensure the changes don't affect the hash output.

Running the benchmark on my machine (Macbook M3) with mocked data, I got the following results:

  • Old algorithm:
test project::test::bench_hash_files ... bench: 124,114,604.10 ns/iter (+/- 4,436,905.96)
  • New algorithm:
test project::test::bench_hash_files ... bench: 109,505,895.80 ns/iter (+/- 2,963,416.66)

We could improve more if we changed the algorithm to hash each file independently and then accumulate all the resulting hashes. However, this would change the resulting hash and is probably not worth it.

Close STY-158

Read the files in a separate thread and then send the keccak preimage
through a channel to the main thread.
This improves the performance in ~13% without changing the hash output.
@gligneul gligneul marked this pull request as draft November 4, 2024 12:35
@gligneul gligneul marked this pull request as ready for review November 4, 2024 14:29
Copy link
Member

@joshuacolvin0 joshuacolvin0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joshuacolvin0 joshuacolvin0 merged commit fbcffad into develop Nov 15, 2024
7 checks passed
@joshuacolvin0 joshuacolvin0 deleted the gligneul/audit-m-06 branch November 15, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants